(function(){
  Act.app = {
    Init: function(){
      var me = this;
      Ext.Loader.setPath('Ext.ux', 'asset/ext/ux');
      Ext.QuickTips.init();

      Ext.create('Ext.Viewport', {
        minWidth: 1e3,
        minHeight: 500,
        layout: "border",
        items: [ me.Top(), me.Left(), me.Center() ]
      });

      Act.AddTab('home', '首页', '/example')
    },
    Top: function(){
      return {
        region: 'north',
        layout: 'fit',
        border: false,
        height: 36,
        items: [{
          xtype: 'toolbar',
          defaults: {
            xtype: 'buttontransparent'
          },
          items: [{
            xtype: 'image',
            margin: '15 5 0 10',
            width: 16,
            height: 16,
            src: '/asset/img/logo.png'
          },{
            xtype: 'label',
            text: 'ActBuilder',
            baseCls: 'index-title'
          },{
            xtype: 'label',
            text: '(1.0.0)',
            baseCls: 'index-title-ver'
          },'->',{
            xtype: 'label',
            text: '当前账号:超级管理员',
            margin: '0 5 0 0'
          },{
            id: 'homepagebutton',
            text: '系统首页',
            action: 'homepage',
            icon: '/asset/img/button/homepage.png'
          },{
            text: '修改密码',
            icon: '/asset/img/button/resetpassword.png'
          }, {
            text: '退出系统',
            action: 'logout',
            icon: '/asset/img/button/return.png'
          }]
        }]
      }
    },
    Left: function(){
      return {
        region: 'west',
        layout: 'fit',
        title: '我的导航',
        split: true,
        frame: false,
        closable: false,
        collapsible: true,
        margin: '3 0 0 0',
        items: [{
          layout: 'accordion',
          width: 220,
          border: false,
          items: [ Act.app.CreateMenu(), Act.app.CreateMenu() ]
        }]
      }
    },
    Center: function(){
      return Act.mainTab = Ext.create('Ext.tab.Panel', {
        region: 'center',
        closeAction: 'hide',
        autoDestroy: false,
        layout: 'fit',
        plugins: [{
          ptype: 'tabclosemenu',
          closeAllTabsText: '关闭所有',
          closeOthersTabsText: '关闭其他',
          closeTabText: '关闭'
        }, Ext.create('Ext.ux.TabReorderer')],
        margin: '3 0 0 0',
      })
    },
    CreateMenu: function(){
      return {
        title: '基础数据',
        layout: 'fit',
        dockedItems: {
          xtype: 'toolbar',
          border: false,
          items: [{
            text: '展开',
            icon: '/asset/img/button/expanded.png'
          },{
            text:'折叠',
            icon: '/asset/img/button/collapsed.png'
          },{
            text: '刷新',
            icon: '/asset/img/button/refresh.png'
          }]
        },
        items: [{
          xtype: 'treepanel',
          border: false,
          rootVisible: false,
          root: {
            expanded: true,
            text: 'Root',
            children: [{
              text: '页面管理',
              expanded: false,
              leaf: true
            },{
              text: '导航目录',
              expanded: false,
              leaf: true
            }]
          },
          listeners: {
            'itemclick': function(view, record, item, index, e){
              // App.addNewTab('aaa-333-33344','/dbe');
              console.log(record);
              Act.AddTab('dbe','数据库','/dbe');
            }
          }
        }]
      }
    }
  }
})()